<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form id="form" action=""  method="post" onsubmit="return false">
		姓名：<input type="text" name="name"/><br/>
		密码：<input type="text" name="password"/><br/>
		邮箱：<input type="text" name="email"/><br/>
		年龄：<input type="text" name="age"/><br/>
		入职日期：<input id="joindate" type="text" name="joindate"/><br/>
		<button  onclick="add()">添加</button>		
	</form>
	
	<script src="<%=request.getContextPath()%>/static/lib/jquery/jquery-1.11.1.js"></script>
	<script src="${pageContext.request.contextPath}/static/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/common/mylayer.js"></script>
	<script type="text/javascript">
		// 加载layer这个模块
		layui.use(['layer','laydate'], function(){
			var table = layui.table;
			var laydate = layui.laydate;
			
			//常规用法
		    laydate.render({
		      elem: '#joindate'
		    });
		});
		
		function add() {
			$.ajax({
		  	  url : "${pageContext.request.contextPath}/user/add.action",
		  	  data : $("#form").serialize(),
		  	  dataType : "json",
		  	  success : function(resp) {
		  		  if(resp.code == 0) {
		  			  mylayer.success(resp.msg);
		  			  //先得到当前iframe层的索引
		              var index = parent.layer.getFrameIndex(window.name);
		  			  //定时一秒后执行
		              setTimeout(function() {
		            	  //关闭当前弹出层
		                  parent.layer.close(index);
		                  //刷新父页面,刷新table
		                  window.parent.location.reload();
		               }, 1000);
		  		  } else {
		  			  mylayer.error(resp.msg);
		  		  }
		  	  }
		    });
		}
	</script>
</body>
</html>